//
//  ZMTabBarController.swift
//  ZMWeiboSwift
//
//  Created by pg on 2017/7/22.
//  Copyright © 2017年 pg. All rights reserved.
//

import UIKit

class ZMTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
       //设置当前导航控制器为自定义的导航条
        let tab = ZMTabBar()
        
        self.setValue(tab, forKey: "tabBar")
        //设置闭包,接受按钮单击事件
        tab.btnclickClosure = {
            //添加按钮单击是执行的操作
            let composeview = ZMComposeView()
            composeview.showComposeView(target: self)
            
         //   let window = UIApplication.shared.keyWindow
          //  window?.addSubview(composeview)
            
        }
       addChildViewController(childviewcontroller: ZMHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(childviewcontroller: ZMMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(childviewcontroller: ZMDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(childviewcontroller: ZMMineViewController(), title: "我的", imageName: "tabbar_profile")
        
        
        
    }

    //MARK:- 添加自控制器
    func addChildViewController(childviewcontroller:UIViewController,title:String,imageName:String) -> Void {
        
       // childviewcontroller.navigationItem.title = title
        
       // childviewcontroller.tabBarItem.title = title
        
        childviewcontroller.title = title
        
        
        childviewcontroller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.darkGray,NSFontAttributeName:UIFont.systemFont(ofSize: 12)], for: UIControlState.normal)
        childviewcontroller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange,NSFontAttributeName:UIFont.systemFont(ofSize: 12)], for: UIControlState.selected)
        
        //设置图片
        childviewcontroller.tabBarItem.image = UIImage(named: imageName)?.withRenderingMode(.alwaysOriginal)
        childviewcontroller.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
        
        let nav  = ZMNavController(rootViewController: childviewcontroller)
        
        
        addChildViewController(nav)
       
    }
    
    
}
